*************************************************************
* Replication codes for analyses in Section 6.1 of
* Beyond Yield Response: Weather Shocks and Crop Abandonment
* May 2020
*************************************************************

	use dta\dta_for_silage, replace	
		
* Adjustments on variables

	* take log
		
		foreach x in silage_ha_acres silage_ha_yields {
			gen l_`x' = log(`x') 
			}

	* spline variables
		
		gen gdd8_26 = (dday8C-dday26C)/100
		gen gdd26_35 = dday26C - dday35C
		
	* scale units	
		
		replace prec = prec/100
		gen prec2 = prec^2

	* new time var	
		gen t = year-1980
		gen t2 = t^2
		
	* state-year indicator	
		replace stateansi = floor(fips/1000)
		gen stateyear = stateansi*year			
		
	* generate indicator to drop (very few obs)
		gen drop_corn = inlist(stateansi,10,35,41,49,53,56)
		
	* gen num of yrs for silage
		egen pl_yrs_silage = total(l_silage_ha_acres!=.), by(fips)
	
* regressions
		
	estimates clear		
	xtset fips year	

	qui reghdfe l_silage_ha_acres c.prec##c.prec gdd8_26 gdd26_35 dday35C L_corn_recprice_state ///
		i.stateansi#c.t i.stateansi#c.t2 i.t if irr_ratio < .1 & drop_corn==0 & pl_yrs_silage>5, ///
		absorb(fips) vce(cluster fips stateyear)		
		estimates store Siha_dday26	
		
	qui reghdfe l_silage_ha_yields c.prec##c.prec gdd8_26 dday26 L_corn_recprice_state ///
		i.stateansi#c.t i.stateansi#c.t2 i.t if irr_ratio < .1 & drop_corn==0 & pl_yrs_silage>5, ///
		absorb(fips) vce(cluster fips stateyear)		
		estimates store Siyld_dday26		
		
	qui reghdfe l_silage_ha_acres c.prec##c.prec gdd8_26 gdd26_35 dday35C iv_corn_recprice_state_real ///
		i.stateansi#c.t i.stateansi#c.t2 i.t if irr_ratio < .1 & drop_corn==0 & pl_yrs_silage>5, ///
		absorb(fips) vce(cluster fips stateyear)		
		estimates store Siha_dday26_iv
		
	qui reghdfe l_silage_ha_yields c.prec##c.prec gdd8_26 dday26 iv_corn_recprice_state_real ///
		i.stateansi#c.t i.stateansi#c.t2 i.t if irr_ratio < .1 & drop_corn==0 & pl_yrs_silage>5, ///
		absorb(fips) vce(cluster fips stateyear)		
		estimates store Siyld_dday26_iv		
		
	* results (Table 3 & Appendix Table A8)
	esttab Si*_dday*, b(4) se(4) keep(*prec* gdd* dday* *price*) order(gdd8* gdd26* dday* *prec* *price*)		
	
